﻿using ClosedXML.Excel;
using System;
using System.Data;
using System.IO;
using System.Text;
using System.Web;
using System.Web.Mvc;

namespace Apps.Web.Core
{
    public class ImgResult : ActionResult
    { 
        public byte[] ImgData { get; set; }
 
        public ImgResult()
        {

        }
          
        public override void ExecuteResult(ControllerContext context)
        {
            try
            { 
                if (this.ImgData != null && ImgData.Length > 0)
                {
                    context.HttpContext.Response.Clear();

                    // 编码
                    context.HttpContext.Response.ContentEncoding = Encoding.UTF8;

                    // 设置网页ContentType
                    context.HttpContext.Response.ContentType =
                        "application/octet-stream";

                    context.HttpContext.Response.BinaryWrite(ImgData);

                    context.HttpContext.Response.End(); 
                } 
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

       
    }
}